 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TroChoi
{
    public partial class Form1 : Form
    {
    //chú thích chơi
	//không chơi nữa
        int dem=0;
        public void chuyenmau(int x, int y)
        {
            foreach (Control c in this.Controls)
            {
                if (c is Label && c.Name != "label26")
                {
                    if (c.Location.X == x && c.Location.Y == y)
                    {
                        if (c.BackColor == Color.Blue)
                        {
                            c.BackColor = Color.Red;
                            dem++;
                        }
                        else if (c.BackColor == Color.Red)
                        {
                            c.BackColor = Color.Blue;
                            dem--;
                        }
                    }
                }
            }

        }
        public Form1()
        {
            InitializeComponent();
        }


        private void btnReSet_Click(object sender, EventArgs e)
        {
            foreach (Control c in this.Controls)
            {
                if (c is Label && c.Name!="label26")
                {
                    c.BackColor = Color.Blue;
                    c.ResetText();
                }
            }
            dem=0;
            txtRedLight.Text = dem.ToString();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            foreach (Control c in this.Controls)
            {
                if (c is Label && c.Name != "label26")
                {
                    c.BackColor = Color.Blue;
                    c.ResetText();
                }
            }
        }

        private void lbl00_Click(object sender, EventArgs e)
        {
            int x=lbl00.Location.X, y=lbl00.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x-70, y);
            chuyenmau(x+70, y);
            chuyenmau(x, y-70);
            chuyenmau(x, y+70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl01_Click(object sender, EventArgs e)
        {
            int x = lbl01.Location.X, y = lbl01.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl02_Click(object sender, EventArgs e)
        {
            int x = lbl02.Location.X, y = lbl02.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl03_Click(object sender, EventArgs e)
        {
            int x = lbl03.Location.X, y = lbl03.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl04_Click(object sender, EventArgs e)
        {
            int x = lbl04.Location.X, y = lbl04.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl10_Click(object sender, EventArgs e)
        {
            int x = lbl10.Location.X, y = lbl10.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl11_Click(object sender, EventArgs e)
        {
            int x = lbl11.Location.X, y = lbl11.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl12_Click(object sender, EventArgs e)
        {
            int x = lbl12.Location.X, y = lbl12.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl13_Click(object sender, EventArgs e)
        {
            int x = lbl13.Location.X, y = lbl13.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl14_Click(object sender, EventArgs e)
        {
            int x = lbl14.Location.X, y = lbl14.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl20_Click(object sender, EventArgs e)
        {
            int x = lbl20.Location.X, y = lbl20.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl21_Click(object sender, EventArgs e)
        {
            int x = lbl21.Location.X, y = lbl21.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl22_Click(object sender, EventArgs e)
        {
            int x = lbl22.Location.X, y = lbl22.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl23_Click(object sender, EventArgs e)
        {
            int x = lbl23.Location.X, y = lbl23.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl24_Click(object sender, EventArgs e)
        {
            int x = lbl24.Location.X, y = lbl24.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl30_Click(object sender, EventArgs e)
        {
            int x = lbl30.Location.X, y = lbl30.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl31_Click(object sender, EventArgs e)
        {
            int x = lbl31.Location.X, y = lbl31.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl32_Click(object sender, EventArgs e)
        {
            int x = lbl32.Location.X, y = lbl32.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl33_Click(object sender, EventArgs e)
        {
            int x = lbl33.Location.X, y = lbl33.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl34_Click(object sender, EventArgs e)
        {
            int x = lbl34.Location.X, y = lbl34.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl40_Click(object sender, EventArgs e)
        {
            int x = lbl40.Location.X, y = lbl40.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl41_Click(object sender, EventArgs e)
        {
            int x = lbl41.Location.X, y = lbl41.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl42_Click(object sender, EventArgs e)
        {
            int x = lbl42.Location.X, y = lbl42.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl43_Click(object sender, EventArgs e)
        {
            int x = lbl43.Location.X, y = lbl43.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void lbl44_Click(object sender, EventArgs e)
        {
            int x = lbl44.Location.X, y = lbl44.Location.Y;
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            if (dem == 25)
                MessageBox.Show("Bạn đã chiến thắng", "Chúc Mừng",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void btnOneMove_Click(object sender, EventArgs e)
        {
            int x, y;
            Random rand = new Random();
            x = (rand.Next(0, 4)) * 70;
            y = (rand.Next(0, 4)) * 70;
            foreach (Control c in this.Controls)
            {
                if (c is Label && c.Name != "label26")
                {
                    c.BackColor = Color.Red;
                    dem = 25;
                }
            }
            chuyenmau(x, y);
            chuyenmau(x - 70, y);
            chuyenmau(x + 70, y);
            chuyenmau(x, y - 70);
            chuyenmau(x, y + 70);
            txtRedLight.Text = dem.ToString();
            

        }
    }
}
